﻿Imports System.Data.OleDb

Public Class CarADD
    Inherits System.Web.UI.Page

    Protected Sub btnAddnewCar_Click(sender As Object, e As EventArgs) Handles btnAddnewCar.Click

        If FUImage.HasFile Then
            FUImage.SaveAs(Request.MapPath("Pictures") & "/" & FUImage.FileName)

        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("MercedesConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into Car(CarModelName,CarModelYear,CC,CarColour,CarPicture,CarInfoURL, UserIDFK) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tbxCarModelName.Text)
        cmd.Parameters.AddWithValue("@f2", tbxCarModelYear.Text)
        cmd.Parameters.AddWithValue("@f3", tbxCC.Text)
        cmd.Parameters.AddWithValue("@f4", tbxCarColour.Text)
        cmd.Parameters.AddWithValue("@f5", "Pictures/" & FUImage.FileName)
        cmd.Parameters.AddWithValue("@f6", tbxCarInfoURL.Text)
        cmd.Parameters.AddWithValue("@f7", Membership.GetUser(User.Identity.Name).ProviderUserKey)

        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("CarList.aspx")

    End Sub
End Class